package com.example.chartmoudel;

import android.graphics.Color;
import android.support.annotation.NonNull;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.LimitLine;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xy on 2017/12/10.
 */

public class LineChartManager  {


    private static LineChart mChart;

    //初始化表格数据
    public static void init(LineChart chart){
        mChart=chart;
        mChart.getAxisRight().setEnabled(false);
        mChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
        mChart.setNoDataText("暂时没有数据");
        mChart.setNoDataTextColor(Color.RED);
        mChart.getLegend().setEnabled(false);
        mChart.getXAxis().setDrawGridLines(false);
        mChart.getAxisLeft().setDrawGridLines(false);
        mChart.getAxisRight().setDrawGridLines(false);
        mChart.getDescription().setEnabled(false);
    }

    //设置警戒线
    public static void setLimitLine(@NonNull int number, String limitLineNmae){
        YAxis yAxis = mChart.getAxisLeft();
        LimitLine ll   = new LimitLine(number,limitLineNmae);
        ll.setLineWidth(0.5f);
        ll.setLineColor(Color.RED);
        ll.setTextColor(Color.RED);
        ll.setTextSize(12);
        ll.setEnabled(true);
        yAxis.addLimitLine(ll);
    }
    //设置警戒线
    public static void setLimitLine(@NonNull int number){
        YAxis yAxis = mChart.getAxisLeft();
        LimitLine ll   = new LimitLine(number,"");
        ll.setLineWidth(0.5f);
        ll.setLineColor(Color.RED);
        ll.setTextColor(Color.RED);
        ll.setTextSize(12);
        ll.setEnabled(true);
        yAxis.addLimitLine(ll);
    }

    //1:一天
    //2：一周
    //3：一个月
    public static void setXValue(int i){
        final List<String> list=new ArrayList<>();
        switch (i){
            case 1:
                for (int j = 0; j < 24; j++) {
                    list.add(j+":00");
                }
                break;
            case 2:
                list.add("Mon");
                list.add("Tues");
                list.add("Wed");
                list.add("Thur");
                list.add("Fri");
                list.add("Sat");
                list.add("Sun");

                break;
            case 3:
                for (int j = 0; j < 30; j++) {
                    list.add(""+j);
                }
                break;

        }

        IAxisValueFormatter formatter = new IAxisValueFormatter() {

            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                return list.get((int) value);
            }
        };
        XAxis xAxis = mChart.getXAxis();
        xAxis.setValueFormatter(formatter);
    }

    public static void setDataStyle(LineDataSet dataSet){
        dataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
        dataSet.setDrawCircleHole(false);
        dataSet.setDrawValues(false);
    }




}
